home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / nova2001.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  5KB  |  229 lines

  1. /*******************************************************************************
  2.  
  3.      Nova 2001 - Video Description:
  4.      --------------------------------------------------------------------------
  5.  
  6.      Foreground Playfield Chars (static)
  7.         character code index from first set of chars
  8.      Foreground Playfield color modifier RAM
  9.         Char colors are normally taken from the first set of 16,
  10.         This is the pen for "color 1" for this tile (from the first 16 pens)
  11.  
  12.      Background Playfield Chars (scrolling)
  13.         character code index from second set of chars
  14.      Foreground Playfield color modifier RAM
  15.         Char colors are normally taken from the second set of 16,
  16.         This is the pen for "color 1" for this tile (from the second 16 pens)
  17.      (Scrolling in controlled via the 8910 A and B port outputs)
  18.  
  19.      Sprite memory is made of 32 byte records:
  20.  
  21.         Sprite+0, 0x80 = Sprite Bank
  22.         Sprite+0, 0x40 = Sprite Enable
  23.         Sprite+0, 0x3f = Sprite Character Code
  24.         Sprite+1, 0xff = X location
  25.         Sprite+2, 0xff = Y location
  26.         Sprite+3, 0x40 = Y Flip
  27.         Sprite+3, 0x20 = X Flip
  28.         Sprite+4, 0x0f = pen for "color 1" taken from the first 16 colors
  29.  
  30.         All the rest are unknown and/or uneccessary.
  31.  
  32. *******************************************************************************/
  33.  
  34. #include "vidhrdw/generic.h"
  35.  
  36. unsigned char *nova2001_videoram,*nova2001_colorram;
  37. size_t nova2001_videoram_size;
  38.  
  39. static int nova2001_xscroll;
  40. static int nova2001_yscroll;
  41. static int flipscreen;
  42.  
  43.  
  44.  
  45. void nova2001_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  46. {
  47.     int i,j;
  48.  
  49.  
  50.     for (i = 0;i < Machine->drv->total_colors;i++)
  51.     {
  52.         int intensity;
  53.  
  54.  
  55.         intensity = (*color_prom >> 0) & 0x03;
  56.         /* red component */
  57.         *(palette++) = (((*color_prom >> 0) & 0x0c) | intensity) * 0x11;
  58.         /* green component */
  59.         *(palette++) = (((*color_prom >> 2) & 0x0c) | intensity) * 0x11;
  60.         /* blue component */
  61.         *(palette++) = (((*color_prom >> 4) & 0x0c) | intensity) * 0x11;
  62.  
  63.         color_prom++;
  64.     }
  65.  
  66.     /* Color #1 is used for palette animation.          */
  67.  
  68.     /* To handle this, color entries 0-15 are based on  */
  69.     /* the primary 16 colors, while color entries 16-31 */
  70.     /* are based on the secondary set.                  */
  71.  
  72.     /* The only difference among 0-15 and 16-31 is that */
  73.     /* color #1 changes each time */
  74.  
  75.     for (i = 0;i < 16;i++)
  76.     {
  77.         for (j = 0;j < 16;j++)
  78.         {
  79.             if (j == 1)
  80.             {
  81.                 colortable[16*i+1] = i;
  82.                 colortable[16*i+16*16+1] = i+16;
  83.             }
  84.             else
  85.             {
  86.                 colortable[16*i+j] = j;
  87.                 colortable[16*i+16*16+j] = j+16;
  88.             }
  89.         }
  90.     }
  91. }
  92.  
  93.  
  94.  
  95. WRITE_HANDLER( nova2001_scroll_x_w )
  96. {
  97.     nova2001_xscroll = data;
  98. }
  99.  
  100. WRITE_HANDLER( nova2001_scroll_y_w )
  101. {
  102.     nova2001_yscroll = data;
  103. }
  104.  
  105.  
  106.  
  107. WRITE_HANDLER( nova2001_flipscreen_w )
  108. {
  109.     if ((~data & 0x01) != flipscreen)
  110.     {
  111.         flipscreen = ~data & 0x01;
  112.         memset(dirtybuffer,1,videoram_size);
  113.     }
  114. }
  115.  
  116.  
  117.  
  118. /***************************************************************************
  119.  
  120.   Draw the game screen in the given osd_bitmap.
  121.   Do NOT call osd_update_display() from this function, it will be called by
  122.   the main emulation engine.
  123.  
  124. ***************************************************************************/
  125. void nova2001_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  126. {
  127.     int offs;
  128.  
  129.  
  130.     /* for every character in the Video RAM, check if it has been modified */
  131.     /* since last time and update it accordingly. */
  132.     for (offs = videoram_size - 1;offs >= 0;offs--)
  133.     {
  134.         if (dirtybuffer[offs])
  135.         {
  136.             int sx,sy;
  137.  
  138.  
  139.             dirtybuffer[offs] = 0;
  140.  
  141.             sx = offs % 32;
  142.             sy = offs / 32;
  143.             if (flipscreen)
  144.             {
  145.                 sx = 31 - sx;
  146.                 sy = 31 - sy;
  147.             }
  148.  
  149.             drawgfx(tmpbitmap,Machine->gfx[1],
  150.                     videoram[offs],
  151.                     colorram[offs] & 0x0f,
  152.                     flipscreen,flipscreen,
  153.                     8*sx,8*sy,
  154.                     0,TRANSPARENCY_NONE,0);
  155.         }
  156.     }
  157.  
  158.  
  159.     {
  160.         int scrollx,scrolly;
  161.  
  162.         if (flipscreen)
  163.         {
  164.             scrollx = nova2001_xscroll;
  165.             scrolly = nova2001_yscroll;
  166.         }
  167.         else
  168.         {
  169.             scrollx = -nova2001_xscroll;
  170.             scrolly = -nova2001_yscroll;
  171.         }
  172.  
  173.         copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  174.     }
  175.  
  176.  
  177.     /* Next, draw the sprites */
  178.     for (offs = 0;offs < spriteram_size;offs += 32)
  179.     {
  180.         if (spriteram[offs+0] & 0x40)
  181.         {
  182.             int sx,sy,flipx,flipy;
  183.  
  184.  
  185.             sx = spriteram[offs+1];
  186.             sy = spriteram[offs+2];
  187.             flipx = spriteram[offs+3] & 0x10;
  188.             flipy = spriteram[offs+3] & 0x20;
  189.             if (flipscreen)
  190.             {
  191.                 sx = 240 - sx;
  192.                 sy = 240 - sy;
  193.                 flipx = !flipx;
  194.                 flipy = !flipy;
  195.             }
  196.  
  197.             drawgfx(bitmap,Machine->gfx[2 + ((spriteram[offs+0] & 0x80) >> 7)],
  198.                     spriteram[offs+0] & 0x3f,
  199.                     spriteram[offs+3] & 0x0f,
  200.                     flipx,flipy,
  201.                     sx,sy,
  202.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  203.         }
  204.     }
  205.  
  206.  
  207.     /* Finally, draw the foreground text */
  208.     for (offs = nova2001_videoram_size - 1;offs >= 0;offs--)
  209.     {
  210.         int sx,sy;
  211.  
  212.  
  213.         sx = offs % 32;
  214.         sy = offs / 32;
  215.         if (flipscreen)
  216.         {
  217.             sx = 31 - sx;
  218.             sy = 31 - sy;
  219.         }
  220.  
  221.         drawgfx(bitmap,Machine->gfx[0],
  222.                 nova2001_videoram[offs],
  223.                 nova2001_colorram[offs] & 0x0f,
  224.                 flipscreen,flipscreen,
  225.                 8*sx,8*sy,
  226.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  227.     }
  228. }
  229.